package com.briup.product_source.service.impl;

import com.briup.product_source.dao.QuarantineRegistrationMapper;
import com.briup.product_source.exception.ServiceException;
import com.briup.product_source.pojo.QuarantineRegistration;
import com.briup.product_source.service.QuarantineRegistrationService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QuarantineRegistrationServiceImpl implements QuarantineRegistrationService {
    @Autowired
    private QuarantineRegistrationMapper qrMapper;
    @Override
    public PageInfo<QuarantineRegistration> findByPage(Integer pageNum, Integer pageSize,
                                                       String mechanism, String bQualified) {
    //1.开启分页查询
        PageHelper.startPage(pageNum, pageSize);

        //2.执行条件查询
        List<QuarantineRegistration> list = qrMapper.selectAllRecord(mechanism, bQualified);

        //3.封装分页对象并返回
        PageInfo<QuarantineRegistration> pageInfo = new PageInfo(list);
        return pageInfo;
    }
    @Override
    public void saveOrUpdate(QuarantineRegistration qr) throws ServiceException {
    //1.参数校验
    //2.批次校验【保证该批次存在】
    //3.执行更新或更新，返回受影响的行数result
    //3.1 有id->更新操作
    //3.2 无id->新增操作
    //4.结果判断：如果影响行数为0，则抛出异常
    //5.修改指定批次检疫状态为"已检疫"及检疫合格状态 bQualified
    }
}
